package saiboten.actions;

import java.util.LinkedList;

import org.jibble.pircbot.PircBot;

import saiboten.SenderAction;

public class LastLinksAction implements SenderAction {
	
	java.util.Queue<String> lastLinks = new LinkedList<String>();

	@Override
	public void action(PircBot bot, String sender, String message) {
		if (message.equalsIgnoreCase("!lastlinks")) {
			String lastLinkText = "Siste lenker: ";
			for (String link : lastLinks) {
				lastLinkText += link + " - ";
			}
			lastLinkText = lastLinkText.substring(0, lastLinkText.length() - 3);
			bot.sendMessage(sender, lastLinkText);
		}

		if (message.contains("http://")) {
			String[] words = message.split(" ");
			for (String word : words) {
				if (word.contains("http://")) {
					System.out.println("La til lenken: " + word);
					lastLinks.add(word);
					if (lastLinks.size() > 5) {
						System.out.println("Fjernet en lenke.");
						lastLinks.remove();
					}
				}
			}
		}
		
	}
}
